From: Florian Müllner Date: Thu, 19 Dec 2019 02:28:50 +0000 (+0100) Subject: grabHelper: Add (promised-based) grabAsync() X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~781^2^2~288 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=93fa1034f51594fa4e61d2f8bde8ecdae39ddbdc;p=gnome-shell.git grabHelper: Add (promised-based) grabAsync() Some GrabHelper uses are in the form: doPreGrabStuff(); this._grabHelper.grab({ onUngrab: () => { undoPreGrabStuff(); }, }); A promise-based variant allows to write this more cleanly as: doPreGrabStuff(); await this._grabHelper.grabAsync(); undoPreGrabStuff(); https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/903 --- diff --git a/js/ui/grabHelper.js b/js/ui/grabHelper.js index ffe07b2ec..2ba2aad9a 100644 --- a/js/ui/grabHelper.js +++ b/js/ui/grabHelper.js @@ -194,6 +194,15 @@ var GrabHelper = class GrabHelper { return true; } + grabAsync(params) { + return new Promise((resolve, reject) => { + params.onUngrab = resolve; + + if (!this.grab(params)) + reject(new Error('Grab failed')); + }); + } + _takeModalGrab() { let firstGrab = this._modalCount == 0; if (firstGrab) {